package eleven;

/**
 * 318. 最大单词长度乘积（中等）
 *
 */
public class Day06 {
    public int maxProduct(String[] words){
        int[] mask = new int[words.length];//位运算 保存每个单词26个字母的情况
        for (int i = 0; i <words.length; i++) {
            mask[i] = 0;
            for (int j = 0; j < words[i].length(); j++) {
                mask[i] |= 1 << (words[i].charAt(j)-'a');// 0~25
            }
        }
        int maxMulti = 0;
        for (int i = 0; i <words.length; i++) {
            for (int j = i+1; j < words.length; j++) {
                if ((mask[i] & mask[j]) == 0){
                    maxMulti = Math.max(maxMulti,words[i].length()*words[j].length());
                }
            }
        }
        return maxMulti;
    }
    public static void main(String[] args) {
        Day06 day06 = new Day06();
        String[] words = {"a","ab","abc","d","cd","bcd","abcd"};
        System.out.println(day06.maxProduct(words));
    }
}
